package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import javax.swing.*;

public class EditPage extends Utils {
    private static String url = "http://127.0.0.1:8080/blog_edit.html";

    public EditPage() {
        super(url);
    }

    //检查写博客页面是否可运行
    public void EdieSuc(){
        //由于该页面使用的编辑框为第三方插件，不可直接sendKeys，这里使用键盘鼠标操作模拟实现
        Actions action = new Actions(driver);
        WebElement ele = driver.findElement(By.cssSelector("#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre"));
        action.doubleClick(ele).perform();    //双击对象
        action.keyDown(Keys.DELETE).perform();  //删除原内容
        action.moveToElement(ele).sendKeys("通过鼠标键盘操作键入测试博客");   //输入内容
        driver.findElement(By.cssSelector("#submit")).click();  //点击提交



    }
}
